package com.mMap.service.impl;

import com.mMap.component.RedisComponent;
import com.mMap.entity.config.AppConfig;
import com.mMap.entity.constants.Constants;
import com.mMap.entity.dto.SessionWebUserDto;
import com.mMap.entity.enums.PageSize;
import com.mMap.entity.enums.UserStatusEnum;
import com.mMap.entity.po.OrderInfo;
import com.mMap.entity.query.SimplePage;
import com.mMap.entity.query.OrderInfoQuery;
import com.mMap.entity.vo.PaginationResultVO;
import com.mMap.exception.BusinessException;
import com.mMap.mappers.OrderInfoMapper;
import com.mMap.service.OrderInfoService;
import com.mMap.service.OrderInfoService;
import com.mMap.utils.StringTools;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;


/**
 * 订单信息 业务接口实现
 */
@Service("orderInfoService")
public class OrderInfoServiceImpl implements OrderInfoService {

    @Resource
    private OrderInfoMapper<OrderInfo, OrderInfoQuery> orderInfoMapper;


//    @Resource
//    private FileInfoService fileInfoService;

    @Resource
    private AppConfig appConfig;

    @Resource
    private RedisComponent redisComponent;
    private static final Logger logger = LoggerFactory.getLogger(OrderInfoServiceImpl.class);

    /**
     * 根据条件查询列表
     */
    @Override
    public List<OrderInfo> findListByParam(OrderInfoQuery param) {
        return this.orderInfoMapper.selectList(param);
    }

    /**
     * 根据条件查询列表
     */
    @Override
    public Integer findCountByParam(OrderInfoQuery param) {
        return this.orderInfoMapper.selectCount(param);
    }

    /**
     * 分页查询方法
     */
    @Override
    public PaginationResultVO<OrderInfo> findListByPage(OrderInfoQuery param) {
        int count = this.findCountByParam(param);
        int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

        SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
        param.setSimplePage(page);
        List<OrderInfo> list = this.findListByParam(param);
        PaginationResultVO<OrderInfo> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
        return result;
    }

    /**
     * 新增
     */
    @Override
    public Integer add(OrderInfo bean) {
        return this.orderInfoMapper.insert(bean);
    }

    /**
     * 根据OrderId获取对象
     */
    @Override
    public OrderInfo getOrderInfoByOrderId(String orderId) {
        return this.orderInfoMapper.selectByOrderId(orderId);
    }

    /**
     * 根据OrderId修改
     */
    @Override
    public Integer updateOrderInfoByOrderId(OrderInfo bean, String orderId) {
        return this.orderInfoMapper.updateByOrderId(bean, orderId);
    }

    /**
     * 根据OrderId删除
     */
    @Override
    public Integer deleteOrderInfoByOrderId(String orderId) {
        return this.orderInfoMapper.deleteByOrderId(orderId);
    }

}